package school.test;

import java.util.HashMap;
import java.util.Map;
import school.course.Course;
import school.person.Student;
import school.person.Teacher;

public class TestMain {
    public static void main(String[] args) {
        // 存储课程、教师、学生的映射
        Map<String, Course> courseMap = new HashMap<>();
        Map<String, Teacher> teacherMap = new HashMap<>();
        Map<String, Student> studentMap = new HashMap<>();

        // 创建课程
        Course course1 = new Course("C001", "Java程序设计", "教学楼A101", "周一8:00-10:00", "T001");
        Course course2 = new Course("C002", "数据结构", "教学楼B202", "周三14:00-16:00", "T002");
        courseMap.put(course1.getCourseId(), course1);
        courseMap.put(course2.getCourseId(), course2);

        // 创建教师
        Teacher teacher1 = new Teacher("T001", "张老师", "男", "C001");
        Teacher teacher2 = new Teacher("T002", "李老师", "女", "C002");
        teacherMap.put(teacher1.id, teacher1);  // 访问父类protected属性
        teacherMap.put(teacher2.id, teacher2);

        // 创建学生
        Student student1 = new Student("S001", "小明", "男");
        Student student2 = new Student("S002", "小红", "女");
        studentMap.put(student1.id, student1);  // 访问父类protected属性
        studentMap.put(student2.id, student2);

        // 教师开课信息（测试继承的toString）
        System.out.println("教师开课情况：");
        System.out.println(teacher1);
        System.out.println(teacher2);

        // 学生选课
        System.out.println("\n学生选课情况：");
        student1.selectCourse("C001");
        student1.selectCourse("C002");
        student2.selectCourse("C001");
        System.out.println(student1);
        System.out.println(student2);

        // 学生退课
        System.out.println("\n学生退课情况：");
        student1.dropCourse("C002");
        System.out.println(student1);

        // 测试父类方法
        System.out.println("\n测试父类printInfo方法：");
        teacher1.printInfo();
        student1.printInfo();

        // 测试子类实现的工作单方法
        System.out.println("\n测试工作单方法：");
        printStudentCourseSchedule(student1, courseMap, teacherMap);
        printStudentCourseSchedule(student2, courseMap, teacherMap);
    }

    // 打印学生课表
    public static void printStudentCourseSchedule(Student student, Map<String, Course> courseMap, Map<String, Teacher> teacherMap) {
        student.printWorksheet();  // 调用子类实现的父类方法
        for (String courseId : student.getCourseIds()) {
            Course course = courseMap.get(courseId);
            if (course != null) {
                Teacher teacher = teacherMap.get(course.getTeacherId());
                if (teacher != null) {
                    System.out.println("课程编号: " + course.getCourseId() +
                            ", 名称: " + course.getCourseName() +
                            ", 地点: " + course.getLocation() +
                            ", 时间: " + course.getTime() +
                            ", 教师: " + teacher.getName());
                }
            }
        }
        System.out.println("----------------------");
    }
}